/**
 * 数据库测试工具
 * 用于调试IndexedDB数据问题
 */

import { hospitalDB } from './indexedDB'

export const testDatabase = async () => {
  console.log('=== 开始测试数据库 ===')
  
  try {
    // 测试医院数据
    console.log('1. 测试医院数据...')
    const hospitals = await hospitalDB.getHospitals()
    console.log('医院数量:', hospitals?.length || 0)
    console.log('医院列表:', hospitals)
    
    // 测试建筑数据
    if (hospitals && hospitals.length > 0) {
      console.log('2. 测试建筑数据...')
      const buildings = await hospitalDB.getHospitalBuildingsByHospital(hospitals[0].id)
      console.log('建筑数据:', buildings)
      
      // 测试科室数据
      console.log('3. 测试科室数据...')
      const departments = await hospitalDB.getDepartmentsByHospital(hospitals[0].id)
      console.log('科室数据:', departments)
      
      // 测试设备数据
      console.log('4. 测试设备数据...')
      const equipment = await hospitalDB.getMedicalEquipmentByHospital(hospitals[0].id)
      console.log('设备数据:', equipment)
    }
    
    console.log('=== 数据库测试完成 ===')
    return true
  } catch (error) {
    console.error('数据库测试失败:', error)
    return false
  }
}

// 浏览器控制台测试函数
if (typeof window !== 'undefined') {
  (window as any).testDB = testDatabase
  (window as any).hospitalDB = hospitalDB
}